<!--
 * @Author: CNN 969682281@qq.com
 * @Date: 2023-03-07 13:36:39
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-05-22 11:40:22
 * @FilePath: \newMould_BHZ\src\views\WaterManage\trends\instantly.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <!-- 水稳----动态监控---实时监控 -->
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->

        <div class="mechanism_nav_left" style="width: 100%">
          <vDatePicker
            :defaultDate="value2"
            @selectPickDate="selectTime"
            width="215px !important"
          >
          </vDatePicker>
          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.buildPart"
            placeholder="工程部位"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in sgbwList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>

          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.stationId"
            placeholder="所有拌和站"
            @change="selectBhzFun"
          >
            <el-option
              v-for="v in bhzDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>

          <el-select
            class="selectBhz"
            style="width: 160px"
            v-model="getList.machineId"
            placeholder="所有拌和机"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in bhjDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>

          <el-select
            class="selectCondition"
            v-model="getList.warningLevel"
            placeholder="预警等级"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in djDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>

          <el-select
            class="selectCondition"
            v-model="getList.fCloseoperation"
            placeholder="闭合状态"
            @change="yj_searchForm(getList)"
          >
            <el-option
              v-for="v in CloseoperationDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
        </div>
        <!-- 顶部按钮 -->
        <div class="print"></div>
      </div>

      <!-- 表格 -->
      <div class="text_table">
        <!-- <div :id="('select' + index)" v-for="(item, index) in tableData" :key="index">12</div> -->
        <tableData
          :height="navigatepageNums > 1 ? 'calc(100% - 50px)' : '100%'"
          :config="table_config"
          :dataList="tableData"
          :loading="listLoading"
          @selection-change="selectionChange"
          @sort-change="sortChange"
          @click-change="rowChange"
          @openDialog="yj_viewForm"
          :page="getList.page"
          :pageSize="getList.pageSize"
        />

        <pagination
          :info="queryCriteriaData"
          v-if="navigatepageNums > 1"
          :treelength="treelength"
          :total="queryCriteriaData.total"
          :pageNum.sync="getList.page"
          :limit.sync="getList.pageSize"
          @pagination="yj_searchForm(getList)"
        />
      </div>

      <!--弹框 查看 -->
      <div class="Control-1 mechanism_dialogS">
        <el-dialog
          title="查看"
          :modal-append-to-body="false"
          v-dialogDrag
          :visible.sync="dialogEditVisible"
          v-loading="loadingEditDialog"
          element-loading-text="拼命加载中"
          element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.2)"
        >
          <div class="dialogBody common" :style="{ height: '550px' }">
            <div class="baseTitle">基本信息</div>
            <div style="height: 160px">
              <publicForm
                ref="publicForm"
                lableWidth="95px"
                :formObj="formObj"
                :formData="formData"
              >
              </publicForm>
            </div>
            <div class="baseTitle">材料用量</div>
            <div
              style="height: 168px; margin-top: 8px"
              class="levelClass materialClass"
            >
              <tableData
                :config="material_config"
                :dataList="materialData"
                statusType="3"
                :level="level"
                :earlyWarning="earlyWarning"
                :currentRow="false"
                :stripe="false"
              />
            </div>
          </div>
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import vDatePicker from "@/components/public/v-DatePicker"; //时间选择器
import tree from "@/components/public/waterManage_tree"; //左侧机构树
import TableData from "@/components/stationProductionPage/waterManage/public/el-tables"; //主页面列表
import Pagination from "@/components/public/el-pagination"; //主页面分页
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import publicForm from "@/components/public/el-form.vue"; //弹框form

import formJs from "./regexDetail.js"; //新增弹框配置项
import {
  getUserCompanyTreeList, //左侧机构树接口
  getWaterInfoLists, //主页面列表接口
  getWaterInfoByFid, //主页面列表详情接口
  getStationmachineList, //拌合站列表
  getMachineListByStationId, //拌合机
  getStationmachineByfMachineid, //查询-拌合站信息-详情接口
} from "@/api/request.js";
import { statusTypes } from "@/utils/config"; //配置项
export default {
  name: "instantly",
  components: {
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑
    publicForm, //弹框表格
    Pagination, //分页
    vDatePicker, //时间选择器
  },
  data() {
    return {
      name: "instantly", //按钮配置页面代号
      bhzDataList: [], //拌合站
      bhjDataList: [], //拌合机
      sgbwList: formJs.sgbwList, //顶部下拉框---施工部位
      djDataList: formJs.djDataList, //预警级别
      CloseoperationDataList: formJs.CloseoperationDataList, //闭合状态
      formObj: formJs.formObj, //新增编辑配置参数
      formData: {}, //新增编辑向后台传递对象
      navigatepageNums: null, //是否显示分页
      queryCriteriaData: {}, //分页
      value2: "", //主页面日期筛选绑定值
      xlsxName: null,

      // 列表配置项
      table_config: formJs.table_config,
      tableData: [], //表格列表数据列表
      tableDatas: [], //导出所有数据
      level: [],
      earlyWarning: [], //预警标准
      material_config: formJs.material_config, //材料配置项
      materialData: [], //材料用量列表
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级按钮
      showName: "未选择公司",
      dialogHeight: "470px", //弹框高度
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      // 列表给后端传参
      getList: {
        fCompanyid: "", // 施工标段id，不为空
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", // 拌合站id
        machineId: "", // 拌合机id
        buildPart: "", // 施工部位
        warningLevel: "",
        fCloseoperation: "",
        page: 1, // 当前页数
        pageSize: 20, // 每页显示条数
      },
      companyTree: "", //所有数据

      // 左侧机构树
      treeData: [], //左侧树状图数据
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [],
      userInfo: {}, //登录用户
      treeText: {
        //树状图参数
        companyId: null,
        text: null,
        userId: null,
      },
    };
  },

  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));

    if (JSON.parse(sessionStorage.getItem("yjSmart-waterManage_getLists"))) {
      // this.getList = JSON.parse(sessionStorage.getItem("yjSmart-waterManage_getLists"));

      var dataList = JSON.parse(sessionStorage.getItem("yjSmart-waterManage_getLists"));
      this.getList = {
        fCompanyid: dataList.fCompanyid, // 施工标段id，不为空
        startDates: dataList.startDates, // 开始时间
        endDates: dataList.endDates, // 截至时间
        stationId: dataList.stationId, // 拌合站id
        machineId: dataList.machineId, // 拌合机id
        buildPart: dataList.buildPart, // 施工部位
        page: 1, // 当前页数
        pageSize: 20, // 每页显示条数
      };
      this.getbhjDataMethods(this.getList.stationId);
    }
    if (JSON.parse(sessionStorage.getItem("yjSmart-waterManage_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("yjSmart-waterManage_treeCheck"));
      this.checkData = [id.fCompanyid];
    }

    this.getTree();
    this.getDate();
    // this.btnRole(this.name);
    this.table_config.thead[4]["callback"] = function (rowData) {
      let data = statusTypes[rowData.fWarninglevel];
      if (data) {
        return data.label;
      }
    };
    this.table_config.thead[4]["specialClass"] = function (rowData) {
      let data = statusTypes[rowData.fWarninglevel];
      if (data) {
        return data.className;
      }
    };

    this.table_config.operation.cols = [
      {
        label: "查看",
        type: "primary",
        handleRow: this.handleRow,
      },
    ];
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-instantly"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },

    // 点击当前行
    rowChange(val) {
      return val;
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "2", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("yjSmart-waterManage_treeCheck")
              ).fShortname;
              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.checkData[0] = this.treeData[0].fCompanyid;
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            this.mixingPlantList(0, this.getList);
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.getList.fCompanyid = data.fCompanyid;
      this.mixingPlantList(0, this.getList);
      this.getList.stationId = ""; //拌合站编号
      this.getList.machineId = ""; // 拌和机编号

      this.getList.page = 1;
      this.getList.pageSize = 20;
      this.yj_searchForm(this.getList);
    },
    selectBhzFun(e) {
      this.getList.machineId = "";
      this.getbhjDataMethods(e);
    },

    getbhjDataMethods(data) {
      getMachineListByStationId({ stationId: data })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            this.bhjDataList = [
              {
                fItemName: "所有拌和机",
                fItemValue: "",
              },
            ];
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      if (this.getList.buildPart == "施工部位") {
        data.buildPart = "";
      }
      if (this.getList.machineId == "所有拌合机") {
        data.machineId = "";
      }

      window.sessionStorage.setItem(
        "yjSmart-waterManage_getLists",
        JSON.stringify(data)
      );
      getWaterInfoLists(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            that.tableData = res.data.pageInfo.list;
            that.queryCriteriaData = res.data.pageInfo; //分页信息
            that.navigatepageNums =
              that.queryCriteriaData.navigatepageNums.length;
          } else {
            this.$message.error("获取 列表数据失败", res.msg);
            this.listLoading = false;
          }
        })
        .catch((error) => {
          this.$message.error("获取列表数据 接口报错", error.msg);
          this.listLoading = false;
        });
    },
    // 获取骨料名
    getGlName(data) {
      getStationmachineByfMachineid({ machineId: data })
        .then((res1) => {
          if (res1.errcode == 0) {
            this.material_config.thead[3].label =
              res1.data.yjQmpMsStationmachine.fParm1;
            this.material_config.thead[4].label =
              res1.data.yjQmpMsStationmachine.fParm2;
            this.material_config.thead[5].label =
              res1.data.yjQmpMsStationmachine.fParm3;
            this.material_config.thead[6].label =
              res1.data.yjQmpMsStationmachine.fParm4;
            this.material_config.thead[7].label =
              res1.data.yjQmpMsStationmachine.fParm5;
            this.material_config.thead[8].label =
              res1.data.yjQmpMsStationmachine.fParm6;
          } else {
            this.$message.error("获取骨料名", res1.msg);
          }
        })
        .catch((error) => {
          console.log("获取骨料名接口报错", error.msg);
        });
    },
    // 查看
    yj_viewForm(row) {
      console.log("row", row);
      this.fId = row.fId;
      var id = row.fId;
      this.fPhotofilelist = [];
      if (id != "" && id != null) {
        this.dialogEditVisible = true;
        this.loadingEditDialog = false;

        getWaterInfoByFid({
          fId: id,
          companyId: this.getList.fCompanyid,
        })
          .then((res) => {
            if (res.errcode == 0) {
              var that = this;
              that.loadingEditDialog = false;
              that.dialogEditVisible = true;
              that.formData = res.data;
              that.getGlName(res.data.fMachineid);
              this.materialData = [
                {
                  // fCement2deviatevalue
                  name: "实际称量值(t)",
                  cement1: res.data.fCement1actualweighingvalue,
                  cement2: res.data.fCement2actualweighingvalue,
                  aggregate1: res.data.fAggregate1actualweighingvalue,
                  aggregate2: res.data.fAggregate2actualweighingvalue,
                  aggregate3: res.data.fAggregate3actualweighingvalue,
                  aggregate4: res.data.fAggregate4actualweighingvalue,
                  aggregate5: res.data.fAggregate5actualweighingvalue,
                  aggregate6: res.data.fAggregate6actualweighingvalue,
                  water: res.data.fWateractualweighingvalue,

                  // cement3: "",
                },
                {
                  name: "设定比例(%)",
                  cement1: res.data.fCement1designratio,
                  cement2: res.data.fCement2designratio,
                  aggregate1: res.data.fAggregate1designratio,
                  aggregate2: res.data.fAggregate2designratio,
                  aggregate3: res.data.fAggregate3designratio,
                  aggregate4: res.data.fAggregate4designratio,
                  aggregate5: res.data.fAggregate5designratio,
                  aggregate6: res.data.fAggregate6designratio,
                  water: res.data.fWaterdesignratio,
                },
                {
                  name: "实际比例(%)",
                  cement1: res.data.fCement1actualratio, //水泥1
                  cement2: res.data.fCement2actualratio, //水泥2
                  aggregate1: res.data.fAggregate1actualratio, //骨料1
                  aggregate2: res.data.fAggregate2actualratio, //骨料2
                  aggregate3: res.data.fAggregate3actualratio, //骨料3
                  aggregate4: res.data.fAggregate4actualratio, //骨料4
                  aggregate5: res.data.fAggregate5actualratio, //骨料5
                  aggregate6: res.data.fAggregate6actualratio, //骨料6
                  water: res.data.fWateractualratio, //水
                },
                {
                  name: "偏差(%)",
                  cement1: res.data.fCement1deviatevalue, //水泥1
                  cement2: res.data.fCement2deviatevalue, //水泥2
                  aggregate1: res.data.fAggregate1deviatevalue, //骨料1
                  aggregate2: res.data.fAggregate2deviatevalue, //骨料2
                  aggregate3: res.data.fAggregate3deviatevalue, //骨料3
                  aggregate4: res.data.fAggregate4deviatevalue, //骨料4
                  aggregate5: res.data.fAggregate5deviatevalue, //骨料5
                  aggregate6: res.data.fAggregate6deviatevalue, //骨料6
                  water: res.data.fWaterdeviatevalue, //水
                },
                {
                  name: "预警范围值",
                  show: true,
                  cement1: res.data.fCement1warninginfo, //水泥1
                  cement2: res.data.fCement2warninginfo, //水泥2
                  aggregate1: res.data.fAggregate1warninginfo, //骨料1
                  aggregate2: res.data.fAggregate2warninginfo, //骨料2
                  aggregate3: res.data.fAggregate3warninginfo, //骨料3
                  aggregate4: res.data.fAggregate4warninginfo, //骨料4
                  aggregate5: res.data.fAggregate5warninginfo, //骨料5
                  aggregate6: res.data.fAggregate6warninginfo, //骨料5
                  water: res.data.fWaterwarninginfo, //水
                },
              ];
              this.level = [
                "",
                res.data.fCement1warninglevel,
                res.data.fCement2warninglevel,
                res.data.fAggregate1warninglevel,
                res.data.fAggregate2warninglevel,
                res.data.fAggregate3warninglevel,
                res.data.fAggregate4warninglevel,
                res.data.fAggregate5warninglevel,
                res.data.fAggregate6warninglevel,
                res.data.fWaterwarninglevel,
              ];
              this.earlyWarning = [
                "",
                res.data.fCement1warninginfo,
                res.data.fCement2warninginfo,
                res.data.fAggregate1warninginfo,
                res.data.fAggregate2warninginfo,
                res.data.fAggregate3warninginfo,
                res.data.fAggregate4warninginfo,
                res.data.fAggregate5warninginfo,
                res.data.fAggregate6warninginfo,
                res.data.fWaterwarninginfo,
              ];
            } else {
              this.$message.error(res.msg);
            }
          })
          .catch((error) => {
            this.$message.error(error.msg);
          });
      } else {
        return this.$message.error("请先选择需要查看的数据");
      }
    },

    // 获取拌合站数据
    mixingPlantList(num, datas) {
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "2", // 拌合站类型 1砼，2水稳，3沥青
      };
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            this.bhzDataList = [
              {
                fItemName: "所有拌合站",
                fItemValue: "",
              },
            ];

            arr.map((item) => {
              this.bhzDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          this.$message.error(error.msg);
        });
    },

    // 时间间隔
    // selectTime(e) {
    //   this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
    //   this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
    //   this.xlsxName = e[0] + "至" + e[1] + "水稳拌和站记录数据";

    //   this.yj_searchForm(this.getList);
    // },
    selectTime(e) {
      if (e[0] != "" && e[1] != "") {
        this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
        this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
      } else {
        this.getList.startDates = ""; // 开始时间
        this.getList.endDates = ""; // 截至时间
      }
      this.yj_searchForm(this.getList);
    },

    getDate() {
      if (JSON.parse(sessionStorage.getItem("yjSmart-waterManage_getLists"))) {
        var dataList = JSON.parse(
          sessionStorage.getItem("yjSmart-waterManage_getLists")
        );
        this.getList = {
          fCompanyid: dataList.fCompanyid, // 施工标段id，不为空
          startDates: dataList.startDates, // 开始时间
          endDates: dataList.endDates, // 截至时间
          stationId: dataList.stationId, // 拌合站id
          machineId: dataList.machineId, // 拌合机id
          buildPart: dataList.buildPart, // 施工部位
          page: 1, // 当前页数
          pageSize: 20, // 每页显示条数
        };
        this.value2 = [this.getList.startDates, this.getList.endDates];
        this.xlsxName =
          this.getList.startDates +
          "至" +
          this.getList.endDates +
          "水稳拌和站记录数据";
      } else {
        this.getList.startDates = this.common.getDay(-6) + " " + "00:00:00"; // 开始时间
        this.getList.endDates = this.common.getDay(0) + " " + "23:59:59"; // 截至时间

        this.xlsxName =
          this.common.getDay(-6) +
          "至" +
          this.common.getDay(0) +
          " " +
          "23:59:59" +
          "水稳拌和站记录数据";

        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }
    },
    // 获取页面容器高度
    getHeight() {
      // var h = document.documentElement.clientHeight; //获取页面可见高度
      // this.dialogHeight = h * 0.50 + "px";
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>


<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  border-bottom: 1px solid #0c204d;
  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}

.materialClass /deep/.el-table tr:nth-child(5) {
  display: none;
}
</style>
